package com.spi.soconversion.base.definition;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.spi.soconversion.util.SOCConstants;
import com.spi.soconversion.util.XMLTagConstants;

public class SOCHeaderCharges {
	
	private List<SOCHeaderCharge> orderHeaderChargeList = new ArrayList<SOCHeaderCharge>();
	private BigDecimal headerChargeTotal=new BigDecimal("0");
	
	public boolean addHeaderCharge(SOCHeaderCharge shc) {
		boolean status = false;
		if (!orderHeaderChargeList.contains(shc)) {
			status = orderHeaderChargeList.add(shc);
		}
		return status;
	}

	public boolean removeHeaderCharge(SOCHeaderCharge shc) {
		boolean status = false;
		status = orderHeaderChargeList.remove(shc);

		return status;
	}

	public List<SOCHeaderCharge> getHeaderChargeList() {
		return orderHeaderChargeList;
	}

	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer();

		if(orderHeaderChargeList!=null && orderHeaderChargeList.size()>0)
		{
			sb.append(XMLTagConstants.START_TAG_HEADER_CHARGES);
			Iterator<SOCHeaderCharge> iter=orderHeaderChargeList.iterator();
    		while(iter.hasNext())
	    	{
    			sb.append(SOCConstants.NEW_LINE);
    			sb.append(iter.next().toString());  
			}
    		sb.append(SOCConstants.NEW_LINE);
    		sb.append(XMLTagConstants.END_TAG_HEADER_CHARGES);
    		
		}	
		return sb.toString();
	}
	
	public BigDecimal getHeaderChargeTotal()
	{
		if(orderHeaderChargeList!=null && orderHeaderChargeList.size()>0)
		{
			Iterator<SOCHeaderCharge> iter=orderHeaderChargeList.iterator();			
			while(iter.hasNext())
	    	{
				SOCHeaderCharge charge=iter.next();
				headerChargeTotal = headerChargeTotal.add(charge.getChargeAmount());    			
			}
		}
		return headerChargeTotal;
	}

}
